use axum::Json;
use ipinfo::IpInfo;
use serde_json::{json, Value};


use crate::code;

pub async fn info() -> Result<Value,Json<Value>>{
    match IpInfo::new(Default::default()) {
        Ok(mut f) => {
            match f.lookup_self_v4().await {
                Ok(r) => Ok(json!(r)),
                Err(e) => Err(code::sys_(e.to_string()))
            }
        },
        Err(e) => Err(code::sys_(e.to_string()))
    }
}
